﻿
@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>系统用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script type="text/html" id="barDemo">
        {{# if(d.isSync=='N'){}}
        <a title="编辑信息" href="javascript:;" lay-event="userEdit"><i class="layui-icon">&#xe642;</i></a>
        {{# }}}
        <a title="重置密码" href="javascript:;" lay-event="reSetPwd"><i class="layui-icon">&#xe669;</i></a>
        <a title="权限分配" href="javascript:;" lay-event="setPower"><i class="layui-icon">&#xe631;</i></a>
        @*<a title="工序设置" href="javascript:;" lay-event="setGx"><i class="layui-icon">&#xe702;</i></a>*@
        {{# if(d.isSync=='N'){}}
        <a title="删除信息" href="javascript:;" lay-event="userDel"><i class="layui-icon">&#xe640;</i></a>  
        {{# }}}
    </script>

</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">
               
                                <input type="text" name="userCode" placeholder="请输入用户账号" autocomplete="off" class="layui-input" id="userCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
     
                                <input type="text" name="username" placeholder="请输入用户名称" autocomplete="off" class="layui-input" id="userName">
                            </div>
              
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach" id="btn-view" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        <button class="layui-btn" id="btn-update" type="button" name="btn_update" onclick="openWin()"><i class="layui-icon"></i>添加</button>
                        <button class="layui-btn" id="btn-sync" onclick="SyncData()"><i class="layui-icon">&#xe641;</i>数据同步</button>
                        <span style="margin-left: 20px; padding: 7px; background-color: #bababa;font-size:xx-small">数据停用</span>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                        <table class="layui-hide" id="userList" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>


    $(function () {
        //获取用户列表
        //获取部门列表
        deptInfo("dept");
        loadData();
        WebPowersShow();      

    })
    function openWin() {
        InfoOpenPage("../System/EditUser?dataId=0", "用户添加", "65%", "80%");
    }
    function SyncData() {
        $.ajax({
            url: "../System/SyncUser",
            type: "post",
            success: function (data) {
                if (data.Result) {
                    layer.msg("同步完成");
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    var currPage = 1;//首先默认值为1，防止出错
    //赋值用户列表
    function loadData() {
        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var laydate = layui.laydate //日期
                , laypage = layui.laypage //分页
                , layer = layui.layer //弹层
                , table = layui.table //表格
                , carousel = layui.carousel //轮播
                , upload = layui.upload //上传
                , element = layui.element //元素操作
                , slider = layui.slider //滑块
            var condition = JSON.stringify(FormToJson("qForm"));
            var dUrl = '../System/getTableList?dataType=user&condition=' + condition;

            //给table赋值
            table.render({
                elem: '#userList'
                , id: "tData"
                , height: 380
                //, width: 1030
                , url: dUrl //数据接口
                //, height: $(document).height() - $('#userList').offset().top - 20
                , height: 'full-200'   //固定高度-即固定表头固定第一行首

                , title: '系统用户表'
                , page: true //开启分页
                , even: true
                , limits: [20, 50, 80, 100]
                , limit: 20 //每页默认显示的数量
                , cols: [[ //表头
                    { field: 'userCode', align: 'center', title: '登录账号', width: '15%', sort: true, fixed: 'left' }
                    , { field: 'userName', align: 'center', title: '用户名称', width: '20%' }
                    , { field: 'userPhone', align: 'center', title: '联系方式', width: '15%' }
                    , { field: 'createTime', align: 'center', title: '创建时间', width: '17%', sort: true, }
                    , { field: 'statusName', align: 'center', title: '是否在职', width: '13%' }
                    , { field: 'isSyncName', align: 'center', title: '同步数据', width: '13%' }
                    , { fixed: 'right', align: 'center', title: '操作', width: '7%', align: 'center', toolbar: '#barDemo' }
                ]], done: function (res, curr, count) {
                    currPage = curr;
                    $.each(res['data'], function (i, obj) {
                        var status = obj["status"];
                        if (status == "N") {
                            TableRowColor('layui-table-main', i, '#bababa');
                        }
                    });
                }
            });

            //监听行工具事件
            table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'reSetPwd') {
                    if (data.isAcc == "1") {
                        layer.msg("同步数据禁止重置密码");
                        return;
                    }
                    layer.confirm('确认重置密码？', {
                        btn: ['是', '否'] //可以无限个按钮
                        , btn2: function (index, layero) {
                            //否
                        }
                    }, function (index) {
                        layer.close(index);
                        $.ajax({
                            url: "../System/reSetPwd",
                            data: { userCode: data.userCode },
                            type: "post",
                            success: function (data) {
                                if (data.Result) {
                                    layer.msg("成功");
                                } else {
                                    layer.msg(data.Message);
                                }
                            }
                        });
                    });
                } else if (layEvent == 'userEdit') {
                    if (data.isSync == "Y") {
                        layer.msg("同步数据禁止修改");
                    } else {
                        var str = data.userName+"-修改";

                        //NewOpenPage("../System/UserPower?userCode=" + data.userCode + "&roleCode=" + data.powerRole, str, "80%", "90%", "tData", currPage, dUrl)
                        InfoOpenPage("../System/EditUser?dataId="+data.id, "用户信息修改", "65%", "80%");
                    }

                } else if (layEvent == 'userDel') {
                    layer.confirm('确认删除吗？', {
                        btn: ['是', '否'] //可以无限个按钮
                        , btn2: function (index, layero) {
                            //否
                        }
                    }, function (index) {
                        $.ajax({
                            url: "../System/DelUserInfo",
                            type: "post",
                            data: { userCode: data.userCode },
                            success: function (rsl) {
                                if (rsl.Result) {
                                    layer.msg("删除成功");
                                } else {
                                    layer.msg("删除失败");
                                }
                                loadData();
                            }
                        });
                        layer.close(index);
                    });
                } else if (layEvent == 'setPower') {
                    var str = data.userName + "(" + data.userCode + ")-权限配置";
                    NewOpenPage("../System/UserPower?userCode=" + data.userCode + "&roleCode=" + data.powerRole, str, "80%", "90%", "tData", currPage, dUrl)
                } else if (layEvent == 'setGx') {
                    var str = data.userName + "(" + data.userCode + ")";
                    OpenPage(str + "工序配置", "../Basis/UserGongXu?userCode=" + data.userCode);
                }
            });
        });
    }
    /**
    部门信息
    **/
    function deptInfo(fileName) {
        $.ajax({
            url: "../System/GetDeptInfo",
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.Result) {
                    var reData = rsl.Data;
                    for (var i = 0; i < reData.length; i++) {
                        $("#" + fileName).append("<option value='" + reData[i].depCode + "'>" + reData[i].depName + "</option>");
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }

            }
        })
    }
</script>